using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Security;
using System.Configuration;
using System.Web.Configuration;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace Starznet.SharePoint.SPDAT.ApplicationPages.Settings
{
    public class MembershipViewRolePage : LayoutsPageBase
    {
        protected SPGridView GvRoleUserList;
        private string sRole;

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (Request.QueryString["RoleName"] != null)
            {
                sRole = Request.QueryString["RoleName"].ToString();

                //Set up the datagrid
                GvRoleUserList.Controls.Clear();

                BoundField oUserField = new BoundField();
                oUserField.DataField = "UserName";
                oUserField.HeaderText =
                    this.GetGlobalResourceObject("szadm", "RoleUserList_UserNameColumn").ToString();
                oUserField.SortExpression = "UserName";
                GvRoleUserList.Columns.Add(oUserField);

                GvRoleUserList.Visible = true;
                GvRoleUserList.DataSource = this.PopulateData();
                GvRoleUserList.DataBind();
            }
        }

        protected DataTable PopulateData()
        {
            DataTable oDT = new DataTable();
            oDT.Columns.Add("UserName");

            DataRow oRow = null;
            foreach (string sUser in Roles.GetUsersInRole(sRole))
            {
                oRow = oDT.NewRow();
                oRow["UserName"] = sUser;

                oDT.Rows.Add(oRow);
            }
            return oDT;
        }
    }
}
